<template>
    <div>
        <van-nav-bar title="发表评论 " left-text="返回" right-text="发布" left-arrow @click-left="onClickLeft"
            @click-right="onClickRight" />
        <div>
            <van-cell-group inset>
                <van-field v-model="message" rows="10" autosize type="textarea" placeholder="评论" />
            </van-cell-group>
        </div>
        <van-uploader style="margin-left: 20px;" v-model="fileList" :after-read="afterRead" />
    </div>
</template>
<script setup>
import { createApp, ref ,onMounted} from 'vue';
import { showToast, Field, CellGroup, Uploader } from 'vant';
import { useRoute } from 'vue-router';
import httpApi from '@/http';
import moment from 'moment';
import { useStore } from 'vuex';
const store = useStore()
const route = useRoute()
const onClickLeft = () => history.back();

const app = createApp();
app.use(Field);
app.use(CellGroup);
app.use(Uploader);

const type = route.params.id

const message = ref('')
const bata = ref({});
const afterRead = (file) => {
    file.status = 'uploading';
    file.message = '上传中...';

    setTimeout(() => {
        file.status = 'failed';
        file.message = '上传失败';
    }, 1000);
};
onMounted(() => {
      httpApi.liveApi.queryBylist({ page:1,pagesize:10, type:type }).then((res) => {
        console.log("加载详情：", res);
        bata.value = res.data.data.result[0]
        console.log(bata)
});
});
const nowDate = moment().format("YYYY-MM-DD HH:mm:ss")
console.log(nowDate)
const onClickRight = function(){
    let params = {
        user_name: store.state.user.user_name,
        content_text: message.value,
        content_type: type,
        // content_cover: store.state.user.user_cover,
        content_time:nowDate,
      }
    httpApi.liveApi.queryByAdd(params).then((res) => {
        console.log("加载详情：", res);
        if (res.data.code == 200) {
          alert('评论成功！')
          onClickLeft()
        }
      });
}

// queryByAdd
</script>
<style lang="scss" scoped></style>